
# $Id: Bdr.pm 149 2013-04-13 05:42:04Z chengxin.cai $

use strict;

package SQConfig::Bdr;

use Switch;
use Carp;

use PerlUtil qw( gen_getter gen_setter );

sub import {
    my $package = shift;
    $package =~ s/.*:://;

    ##export the constructor
    no strict 'refs';
    my ($caller) = caller;
    *{ $caller . '::' . $package} = \&{$package};

    gen_getter( __PACKAGE__, 'as_string' );

    gen_setter( __PACKAGE__, 'add_line' );
}

sub Bdr {
    my @lines = ();

    my $add_line = sub {
        push @lines, @_;
    };

    bless sub {
        my $op = shift;

        switch ($op) {
            case 'add_line'  { return $add_line; }
            case 'as_string' { return join "\n", @lines; }
            else             { croak "Invalid operation $op"; }
        }
    }, __PACKAGE__;

}

use overload q{""} => \&as_string;

1;

